package com.hc.demo.domain;

import java.math.BigDecimal;

/**
 * 购物车实体类
 */
public class Cart {
    private Integer id;
    private String pname;
    //private Double price;//会出现进度丢失
    private BigDecimal price;
    private BigDecimal quantity;
    public Cart() {

    }

    public void setId(Integer id) {
        this.id = id;
    }

    public void setPname(String pname) {
        this.pname = pname;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public void setQuantity(BigDecimal quantity) {
        this.quantity = quantity;
    }

    public Cart(Integer id, String pname, BigDecimal price, BigDecimal quantity) {
        this.id = id;
        this.pname = pname;
        this.price = price;
        this.quantity = quantity;
    }

    public Integer getId() {
        return id;
    }

    public String getPname() {
        return pname;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public BigDecimal getQuantity() {
        return quantity;
    }


    public static void main(String[] args){
//        double a=0.1;
//        double b=0.3;
        BigDecimal a=new BigDecimal(0.1);
        BigDecimal b=new BigDecimal(0.3);
        BigDecimal c=a.add(b);//divide()乘法
        System.out.println(c.doubleValue());

        BigDecimal a2=new BigDecimal("0.1");
        BigDecimal b2=new BigDecimal(""+0.3);//字符串传参更准确
        BigDecimal c2=a2.add(b2);
        System.out.println(c2);
    }

    @Override
    public String toString() {
        return "Cart{" +
                "id=" + id +
                ", pname='" + pname + '\'' +
                ", price=" + price +
                ", quantity=" + quantity +
                '}';
    }
}
